//
//  ByCellIndexDoctor.m
//  jinpuyiyuan_ios
//
//  Created by mc on 2017/12/5.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByCellIndexDoctor.h"

@implementation ByCellIndexDoctor
{
    UIView          *_line;
    UIImageView     *_doctorImg;
    UILabel         *_doctorNameLabel;
    UILabel         *_tagLabel;
    UILabel         *_skillLabel;
}
+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByCellIndexDoctor";
    ByCellIndexDoctor *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _line = [[UIView alloc] init];
    [self addSubview:_line];
    _line.backgroundColor = [UIColor colorWithWhite:0.90 alpha:1];
    
    _doctorImg = [[UIImageView alloc] init];
    [self addSubview:_doctorImg];
  
    _doctorNameLabel = [[UILabel alloc] init];
    [self addSubview:_doctorNameLabel];
    _doctorNameLabel.font = FONT(16);
    
    _tagLabel = [[UILabel alloc] init];
    [self addSubview:_tagLabel];
    _tagLabel.font = FONT(14);
    _tagLabel.textColor = [UIColor lightGrayColor];
    
    _skillLabel = [[UILabel alloc] init];
    [self addSubview:_skillLabel];
    _skillLabel.font = FONT(14);
    _skillLabel.numberOfLines = 0;
    _skillLabel.textColor = [UIColor lightGrayColor];
    
}

- (void)setModel:(ByModelIndexDoctor *)model{
    _model = model;
    [self setNeedsLayout];
}

- (void)layoutSubviews{
    // 测试数据
    _model.name = @"刘运营";
    _model.tag = @"主治医师";
    _model.skill = @"儿科，中医妇科，慢性病，神经科，牙科等";
    _doctorImg.backgroundColor = BY_THEME_COLOR;
    
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(0));
        make.left.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 1));
    }];
    
    [_doctorImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(5));
        make.size.mas_equalTo(CGSizeMake(70, 50));
    }];
    
    CGFloat width = [_model.name getSizeOfString:16].width + 10;
    [_doctorNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_doctorImg.mas_right).offset(10);
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(width, 15));
    }];
    
    [_tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_doctorNameLabel.mas_right);
        make.top.equalTo(@(10));
        make.right.equalTo(@(-10));
        make.height.equalTo(@(15));
    }];
    
    CGFloat height = [_model.skill getRectOfStringWithSize:CGSizeMake(SCREEN_WIDTH - 10 * 3 - 70, MAXFLOAT) font:14].size.height;
    height = MIN(height, 30);
    [_skillLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_doctorNameLabel.mas_left);
        make.top.equalTo(_doctorNameLabel.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10 * 3 -  70, height));
    }];
    
    _doctorNameLabel.text = _model.name;
    _tagLabel.text = _model.tag;
    _skillLabel.text = _model.skill;
    
}

@end
